home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / oopmous.com / MOUSEUNI.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-11-01  |  8.1 KB  |  295 lines

  1. {$I mouseuni.inc}
  2.  
  3. const
  4.     MOUSE_DRIVER_INTERRUPT = $33;
  5. var
  6.     mouse_exists : boolean;
  7.     mouse_visible : boolean;
  8.     mouse_buttons : integer;
  9.     Registers : DOS.Registers;
  10.  
  11. { --------------------------------------------------------------------- }
  12.  
  13. procedure CallMouse(MouseFunction : integer);
  14. begin
  15.     Registers.AX := MouseFunction;
  16.     intr (MOUSE_DRIVER_INTERRUPT, Registers);
  17. end; { CallMouse }
  18.  
  19. { --------------------------------------------------------------------- }
  20.  
  21. function mouse_object.Exists : boolean;
  22. { check if a mouse driver is currently loaded                }
  23. begin
  24.     Exists := mouse_exists;
  25. end;
  26.  
  27. { --------------------------------------------------------------------- }
  28.  
  29. function mouse_object.NumberOfButtons : integer;
  30. { returns the number of available buttons on the mouse            }
  31. begin
  32.     NumberOfButtons := mouse_buttons;
  33. end;
  34.  
  35. { --------------------------------------------------------------------- }
  36.  
  37. procedure mouse_object.Reset;
  38. { reset the mouse driver to its defaults                }
  39. begin
  40.     CallMouse(0);
  41.     Mouse_Exists := Registers.AX <> 0;
  42. end; { Reset }
  43.  
  44. { --------------------------------------------------------------------- }
  45.  
  46. procedure mouse_object.Show;
  47. { Makes the mouse cursor visible.                    }
  48. begin
  49.     if mouse_visible then exit;
  50.     CallMouse(1);
  51.     mouse_visible := true;
  52. end;
  53.  
  54. { --------------------------------------------------------------------- }
  55.  
  56. procedure mouse_object.Hide;
  57. { Makes mouse cursor invisible. Movement and button activity are    }
  58. { still tracked.                            }
  59. begin
  60.     if not mouse_visible then exit;
  61.     CallMouse(2);
  62.     mouse_visible := false;
  63. end;
  64.  
  65. { --------------------------------------------------------------------- }
  66.  
  67. procedure mouse_object.GetStatus(var status, row, column : integer);
  68. { Gets mouse cursor position and button status.                }
  69. begin
  70.     CallMouse (3);
  71.     with Registers do begin
  72.         column := CX;
  73.         row := DX;
  74.         status := BX;
  75.     end;
  76. end; { GetPosition }
  77.  
  78. { --------------------------------------------------------------------- }
  79.  
  80. procedure mouse_object.MoveTo(new_row, new_column : integer);
  81. { Move mouse cursor to new position                    }
  82. begin
  83.     with Registers do begin
  84.         CX := new_column;
  85.         DX := new_row;
  86.     end;
  87.     CallMouse(4);
  88. end;
  89.  
  90. { --------------------------------------------------------------------- }
  91.  
  92. procedure mouse_object.Pressed(button : integer; var result : boolean; var count, row, column : integer);
  93. { Gets pressed info about named button: current status (up/down),    }
  94. { times pressed since last call, position at most recent press.        }
  95. { Resets count and position info. Button 0 is left, 1 is right on    }
  96. { Microsoft mouse.                            }
  97. begin
  98.     with Registers do begin
  99.         BX := button - 1;
  100.         CallMouse(5);
  101.         case button of
  102.             1 : result := AX and $01 <> 0;
  103.             2 : result := AX and $02 <> 0;
  104.             3 : result := AX and $04 <> 0;
  105.         end; { case }
  106.         count := BX;
  107.         column := CX;
  108.         row := DX;
  109.     end; { with }
  110. end;
  111.  
  112. { --------------------------------------------------------------------- }
  113.  
  114. procedure mouse_object.Released(button : integer; var result : boolean; var count, row, column : integer);
  115. { Gets released info about named button: current status (up/down),    }
  116. { times released since last call, position at most recent press.    }
  117. { Resets count and position info. Button 0 is left, 1 is right on    }
  118. { Microsoft mouse.                            }
  119. begin
  120.     with Registers do begin
  121.         BX := button - 1;
  122.         CallMouse(6);
  123.         case button of
  124.             1 : result := AX and $01 <> 0;
  125.             2 : result := AX and $02 <> 0;
  126.             3 : result := AX and $04 <> 0;
  127.         end; { case }
  128.         count := BX;
  129.         column := CX;
  130.         row := DX;
  131.     end; { with }
  132. end;
  133.  
  134. { --------------------------------------------------------------------- }
  135.  
  136. procedure mouse_object.ColRange(horizontal_min, horizontal_max : integer);
  137. { Sets min and max horizontal range for mouse cursor. Moves        }
  138. { cursor inside range if outside when called. Swaps values if        }
  139. { min and max are reversed.                        }
  140. begin
  141.     with Registers do begin
  142.         CX := horizontal_min;
  143.         DX := horizontal_max;
  144.     end; { with }
  145.     CallMouse(7);
  146. end;
  147.  
  148. { --------------------------------------------------------------------- }
  149.  
  150. procedure mouse_object.RowRange(vertical_min, vertical_max : integer);
  151. { Sets min and max vertical range for mouse cursor. Moves        }
  152. { cursor inside range if outside when called. Swaps values if        }
  153. { min and max are reversed.                        }
  154. begin
  155.     with Registers do begin
  156.         CX := vertical_min;
  157.         DX := vertical_max;
  158.     end; { with }
  159.     CallMouse(8);
  160. end;
  161.  
  162. { --------------------------------------------------------------------- }
  163.  
  164. procedure mouse_object.GraphCursor(hHot, vHot : integer; mask_segment, mask_offset : word);
  165. { Sets graphic cursor shape                        }
  166. begin
  167.     with Registers do begin
  168.         BX := hHot;
  169.         CX := vHot;
  170.         DX := mask_offset;
  171.         ES := mask_segment;
  172.     end;
  173.     CallMouse(9);
  174. end;
  175.  
  176. { --------------------------------------------------------------------- }
  177.  
  178. procedure mouse_object.TextCursor(cursor_type : integer; arg1, arg2 : word);
  179. { Sets text cursor type, where 0 = software and 1 = hardware)        }
  180. { For software cursor, arg1 and arg2 are the screen and cursor        }
  181. { masks.  For hardware cursor, arg1 and arg2 specify scan line        }
  182. { start/stop i.e. cursor shape.                        }
  183. begin
  184.     with Registers do begin
  185.         BX := cursor_type;
  186.         CX := arg1;
  187.         DX := arg2;
  188.     end;
  189.     CallMouse(10);
  190. end;
  191.  
  192. { --------------------------------------------------------------------- }
  193.  
  194. procedure mouse_object.Motion(var horizontal_count, vertical_count : integer);
  195. { Reports net motion of cursor since last call to this function        }
  196. begin
  197.     CallMouse(11);
  198.     with Registers do begin
  199.         horizontal_count := CX;
  200.         vertical_count := DX;
  201.     end;
  202. end;
  203.  
  204. { --------------------------------------------------------------------- }
  205.  
  206. procedure mouse_object.InstallTask(mask, task_segment, task_offset : word);
  207. { Installs a user-defined task to be executed upon one or more        }
  208. {   mouse events specified by mask.                    }
  209. begin
  210.     with Registers do begin
  211.         CX := mask;
  212.         DX := task_offset;
  213.         ES := task_segment;
  214.     end;
  215.     CallMouse(12);
  216. end;
  217.  
  218. { --------------------------------------------------------------------- }
  219.  
  220. procedure mouse_object.LightPenOn;
  221. { Turns on light pen emulation. This is the default condition.        }
  222. begin
  223.     CallMouse(13);
  224. end;
  225.  
  226. { --------------------------------------------------------------------- }
  227.  
  228. procedure mouse_object.LightPenOff;
  229. { Turns off light pen emulation.                    }
  230. begin
  231.     CallMouse(14);
  232. end;
  233.  
  234. { --------------------------------------------------------------------- }
  235.  
  236. procedure mouse_object.Ratio(horizontal, vertical : integer);
  237. { Sets mickey-to-pixel ratio, where ratio is R/8. Default is 16        }
  238. {   for vertical, 8 for horizontal                    }
  239. begin
  240.     with Registers do begin
  241.         CX := horizontal;
  242.         DX := vertical;
  243.     end;
  244.     CallMouse(15);
  245. end;
  246.  
  247. { --------------------------------------------------------------------- }
  248.  
  249. procedure mouse_object.ConditionOff(x1, y1, x2, y2 : integer);
  250. { This function hides the mouse if it is in the region when this    }
  251. { function is called.  Afterwards your program must call Show to show    }
  252. { the cursor again.                            }
  253. begin
  254.     if not mouse_visible then exit;
  255.     with Registers do begin
  256.         SI := x2;        { lower x screen coordinates    }
  257.         DI := y2;        { lower y screen coordinates    }
  258.         CX := x1;        { upper x screen coordinates    }
  259.         DX := y1;        { upper y screen coordinates    }
  260.     end;
  261.     CallMouse(16);
  262.     mouse_visible := false;
  263. end;
  264.  
  265. { --------------------------------------------------------------------- }
  266.  
  267. procedure mouse_object.SetThreshold(x : integer);
  268. { Set the threshold speed for doubling the cursor's movements        }
  269. begin
  270.     Registers.DX := x;
  271.     CallMouse(19);
  272. end;
  273.  
  274.  
  275. { --------------------------------------------------------------------- }
  276.  
  277. var    ExitSave: pointer;        { Previous exit procedure    }
  278.  
  279. {$F+} procedure ExitHandler; {$F-}
  280. begin
  281.     ExitProc := ExitSave;    { Chain to other exit procedures    }
  282.     CallMouse(0);
  283. end;
  284.  
  285. { --------------------------------------------------------------------- }
  286.  
  287. begin
  288.     ExitSave := ExitProc;
  289.     ExitProc := @ExitHandler;    { Install our exit procedure    }
  290.     CallMouse(0);
  291.     mouse_exists := Registers.AX <> 0;
  292.     mouse_visible := false;
  293.     mouse_buttons := Registers.BX;
  294. end.
  295.